package Presum;

/**
 * @Classname 数组不可变303
 * @Description TODO
 * @Date 2023/2/15 22:21
 * @Created by xjl
 */
public class 数组不可变303 {

    class NumArray {
        private int[] sums;

        public NumArray(int[] nums) {
            int n = nums.length;
            sums = new int[n + 1];
            for (int i = 0; i < n; i++) {
                sums[i + 1] = sums[i] + nums[i];
            }
        }

        public int sumRange(int left, int right) {
            return sums[right + 1] - sums[left];
        }
    }
}
